package cn.johnyu.util;

import io.milvus.client.MilvusServiceClient;
import io.milvus.param.ConnectParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MilvusUtil {
    protected static final Logger logger = LoggerFactory.getLogger(MilvusUtil.class);
    private static MilvusServiceClient client;

    /**
     * 获取 Milvus 客户端实例
     * @param host Milvus 服务地址
     * @param port Milvus 服务端口
     * @return MilvusServiceClient 实例
     */
    public static MilvusServiceClient getClient(String host, int port) {
        if (client == null) {
            client = new MilvusServiceClient(
                    ConnectParam.newBuilder().withHost(host).withPort(port).build()
            );
        }
        logger.info("获取到的 Milvus 客户端实例: " + client);
        return client;
    }
    /**
     * 关闭 Milvus 客户端连接
     */
    public static void close() {
        if (client != null) {
            logger.info("关闭 Milvus 客户端连接...");
            client.close();
            client = null;
        }
    }
}
